/*
 * Copyright (C) 2019 ~ 2023 Uniontech Software Technology Co.,Ltd.
 *
 * Author:     yanghongwei <yanghongwei@uniontech.com>
 *
 * Maintainer: yanghongwei <yanghongwei@uniontech.com>
 */

#ifndef _CURL_DOWNLOAD_TOOL_
#define _CURL_DOWNLOAD_TOOL_

#include <string>
#include <functional>

typedef std::function<void(bool result, int statusCode, std::string url, std::string filePath)> DownloadCallBackFunction;

class CurlDownloadToolPrivate;
class CurlDownloadTool
{
public:
    CurlDownloadTool();
    ~CurlDownloadTool();

    // 断点续传
    bool enableBrokenDownload();
    void setBrokenDownload(bool enable);
    // 限速下载
    bool enableSpeedLimitDownload();
    void setSpeedLimitDownload(bool enable);
    int speedLimitValue();
    void setSpeedLimitValue(int value);
    // ssl配置
    void setSSLConfiguration(const std::string &caCertFile, const std::string &localCertFile, const std::string &privateKeyFile);
    // 同步下载
    bool download(int &statusCode, const std::string &url, const std::string &filePath, const std::string &md5 = "");
    // 异步下载
    void download(DownloadCallBackFunction cbFun, const std::string &url, const std::string &filePath, const std::string &md5 = "");
    // 获取要下载文件的大小
    uint64_t getDownloadFileSize(const std::string &url);

private:
    CurlDownloadToolPrivate *m_private;
};

#endif